<?php

namespace app\api\controller\group;

use app\api\BaseController;
use app\api\service\GroupActivityService;

class ActivityController extends BaseController
{
    /**
     * 获取当前时间所有有效活动及商品
     * */
    public function index()
    {
       $store_id = $this->request->param('store_id/d');

        if (empty($store_id)){
            return  json(['code' =>0, 'msg' => '非法参数']);
        }

       $activityList =  GroupActivityService::getActivityList($store_id);

       $hotGroupGoodsList = GroupActivityService::getHotActivityGoods($store_id);

       return json(['code' => 1, 'data' => ['activityList' => $activityList, 'hotGroupGoodsList' => $hotGroupGoodsList], 'msg' => '请求成功']);
    }

    /**
     * 获取活动拼团商品
     * */
    public function goods()
    {
        $group_activity_id = $this->request->param('group_activity_id/d');

        if (empty($group_activity_id)){
            return  json(['code' =>0, 'msg' => '非法参数']);
        }

        $activityGoods =  GroupActivityService::getActivityGoods($group_activity_id);

        return json(['code' => 1, 'data' => $activityGoods, 'msg' => '请求成功']);

    }


    /**
     * 根据获取拼团商品详情
     * */
    public function read()
    {
        $group_goods_id = $this->request->param('group_goods_id/d');

        if (empty($group_goods_id)){
            return  json(['code' =>0, 'msg' => '非法参数']);
        }
        $groupGoods = GroupActivityService::findActivityGroupGoods($group_goods_id);

        return json(['code' => 1, 'data' => $groupGoods,'msg' => '请求成功!']);
    }

}